// 数据中心

import { EPokerStatus, ESuit } from "../ConfigEnum"

export class Poker {
  public point: number = -1
  public suit: ESuit = ESuit.HEITAO
  public status: EPokerStatus = EPokerStatus.CLOSE

  constructor(point: number, suit: ESuit, status: EPokerStatus) {
    this.point = point
    this.suit = suit
    this.status = status
  }
}


export class PokerGroup {
  get pokers() {
    return this._pokers
  }
  private _pokers: Poker[] = []
}


export default class GameDB {

  /****************************
   * Public static API
   ****************************/
  public static Create(): GameDB {
    let gameDb = new GameDB()
    return gameDb
  }

  public static readonly CONST_RECEIVE_GROUPS: number = 4
  public static readonly CONST_PLAY_GROUPS: number = 7

  /****************************
   * Public API
   ****************************/

  /****************************
    * Private API
    ****************************/
  constructor() {
    // 初始化牌局结构
    for (let i = 0; i < GameDB.CONST_RECEIVE_GROUPS; i++) {
      let pokerGroup: PokerGroup = new PokerGroup
      this._receiveAreaPokerGroups.push(pokerGroup)
    }
    // 玩牌区
    for (let i = 0; i < GameDB.CONST_PLAY_GROUPS; i++) {
      let pokerGroup: PokerGroup = new PokerGroup
      this._playPokerGroup.push(pokerGroup)
    }
    // 初始化扑克牌
    for (let point = 1; point <= 13; point++) {
      for (let suit = 0; suit < 4; suit++) {
        let poker = new Poker(point, suit, EPokerStatus.CLOSE)
        this._pokers.push(poker)
      }
    }
  }


  /****************************
    * getter &setter
    ****************************/

  public get pokers(): Poker[] {
    return this._pokers
  }
  public get closePokers(): Poker[] {
    return this._closePokers
  }
  public get openPokers(): Poker[] {
    return this._openPokers
  }
  public get receiveAreaPokerGroups(): PokerGroup[] {
    return this._receiveAreaPokerGroups
  }
  public get playPokerGroup(): PokerGroup[] {
    return this._playPokerGroup
  }


  /****************************
    * Property
    ****************************/
  // 所有扑克牌的原始数据
  private _pokers: Poker[] = []

  // 发牌区盖着的扑克
  private _closePokers: Poker[] = []

  // 发牌区掀开的扑克
  private _openPokers: Poker[] = []

  // 收牌区(4)
  private _receiveAreaPokerGroups: PokerGroup[] = []
  // 玩牌区(7)
  private _playPokerGroup: PokerGroup[] = []

}
